import React from 'react'
import {Layout,Image} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import "./tr.css"
import {useSelector,useDispatch,connect} from 'react-redux'

const {Content} = Layout;

const Guide = () => {
  const guideList = useSelector(state=> state.guide.guideList)
  const valueList = useSelector(state=> state.value.valueList)
  const dispatch = useDispatch()
  const columns = [
    {
      title: '指南id',
      key: 'guide_id',
      dataIndex: 'guide_id',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '指南标题',
      key: 'title',
      dataIndex: 'title',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '指南内容',
      key: 'content',
      dataIndex: 'content',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '阅读量',
      key: 'readnum',
      dataIndex: 'readnum',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '指南内容2',
      key: 'brief',
      dataIndex: 'brief',
      valueType: 'text',
      ellipsis:true
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});console.log(valueList)
        }}><Editor ques={interest} url='http://101.34.58.111:8081/examguide'/></div>
        , <a onClick={async ()=>{
          console.log(record)
          await fetch(`http://101.34.58.111:8081/examguide/${record.guide_id}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          }
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];

    const right = {}

    const interest = [
      {name:'guide_id',label:'指南id',tooltip:'最长为24位',placeholder:'输入指南id'},
      {name:'title',label:'指南标题',tooltip:'最长为24位',placeholder:'请输入指南标题'},
      {name:'content',label:'指南内容',placeholder:'输入指南内容'},
      {name:'readnum',label:'阅读量',placeholder:'输入阅读量'},
      {name:'brief',label:'指南内容2',placeholder:'输入指南内容2'}
  ]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280}}>
          <Table title="考研常识管理" columns={columns} right={right} url="http://101.34.58.111:8081/examguide" ques={interest}/>
        </Content>
    )
}

export default connect()(Guide)
